package com.iphanta.community.common.utils;

import com.iphanta.community.common.entity.DataResult;
import org.slf4j.MDC;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 2/11/22 7:37 PM
 */
public enum  ResultUtils {

    SUCCESS("success", "成功"),
    FAIL("fail_unknow_error", "未知异常"),
    FAIL_ON_BUSINESS("fail_on_business", "业务异常"),
    FAIL_ON_ERROR("fail_on_server", "服务异常"),
    FALL_ON_PARAMS("fail_on_params", "非法参数"),
    ;

    private String code;

    private String message;

    ResultUtils(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public DataResult message(String message) {
        DataResult result = new DataResult(MDC.get("requestId"), this.code, message);
        return result;
    }

    public <T> DataResult result(T data) {
        DataResult<T> result = new DataResult(MDC.get("requestId"), this.code, this.message);
        result.setData(data);
        return result;
    }

    public DataResult result() {
        DataResult result = new DataResult(MDC.get("requestId"), this.code, this.message);
        return result;
    }

    public String code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

}
